package com.ajr.core;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class CountryCodes {
	
	static CountryCodes countrycodes = new CountryCodes();
	
	private CountryCodes() {
		
	}
	
	public static String getCountCode(String country) {

		String url = Settings.getInstance().getConnectionURL();
		String user = Settings.getInstance().getUserName();
		String password = Settings.getInstance().getPassword();
		String driver = Settings.getInstance().getDriverClassName();
		
		Statement stmt1 = null;
		ResultSet rs1 = null;
		java.sql.Connection c = null ;
		
		try {
			Class.forName(driver);
			DriverManager.getConnection(url, user, password);
			// Session session = sessionFactory.openSession();
			// java.sql.Connection c =
			// sessionFactory.openSession().connection();
			c = DriverManager.getConnection(url, user,
					password);

			
			
			
			String orderDetailSQL = "select countries_iso_code_2 from countries where countries_name = '"+country+"'";
			
			 stmt1 = c.createStatement();
			 rs1 = stmt1.executeQuery(orderDetailSQL);
//			OrderDetails orderDetails = new OrderDetails();
			if (rs1.next()) {
				String className = rs1.getString("countries_iso_code_2");
				return className;
			}
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
			
		}finally{
			try {
				rs1.close();
				stmt1.close();
				c.close();
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}

		return "SE";
		
		
	}

}
